package routes

import (
	"qimo_lpz/controllers"

	"github.com/gin-gonic/gin"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()

	// 静态文件服务
	r.Static("/assets", "./assets")
	r.Static("/css", "./assets/css")
	r.Static("/js", "./assets/js")
	r.Static("/images", "./assets/images")

	// API路由组
	api := r.Group("/api")
	{
		auth := api.Group("/auth")
		{
			authController := controllers.AuthController{}
			auth.POST("/register", authController.Register)
			auth.POST("/login", authController.Login)
		}

		products := api.Group("/products")
		{
			productController := controllers.ProductController{}
			products.GET("/", productController.GetAllProducts)
			products.GET("/:id", productController.GetProductByID)
			products.POST("/", productController.CreateProduct)
			products.PUT("/:id", productController.UpdateProduct)
			products.DELETE("/:id", productController.DeleteProduct)
		}

		orders := api.Group("/orders")
		{
			orderController := controllers.OrderController{}
			orders.POST("/", orderController.CreateOrder)
			orders.GET("/", orderController.GetUserOrders)
		}
	}

	// 页面路由
	r.GET("/", func(c *gin.Context) {
		c.File("./views/pages/home.html")
	})

	r.GET("/login", func(c *gin.Context) {
		c.File("./views/pages/login.html")
	})

	r.GET("/register", func(c *gin.Context) {
		c.File("./views/pages/register.html")
	})

	r.GET("/products", func(c *gin.Context) {
		c.File("./views/pages/products.html")
	})

	r.GET("/product/:id", func(c *gin.Context) {
		c.File("./views/pages/product_detail.html")
	})

	r.GET("/orders", func(c *gin.Context) {
		c.File("./views/pages/orders.html")
	})

	r.GET("/profile", func(c *gin.Context) {
		c.File("./views/pages/profile.html")
	})

	r.GET("/about", func(c *gin.Context) {
		c.File("./views/pages/about.html")
	})

	r.GET("/contact", func(c *gin.Context) {
		c.File("./views/pages/contact.html")
	})

	r.GET("/admin", func(c *gin.Context) {
		c.File("./views/pages/admin.html")
	})

	return r
}